<template>
	<view>
		<view class="cu-modal" :class="showMolde?'show':'hide'">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">请输入密码</view>
				</view>
				<view class="padding-xl">
					<view class="padding20rpx border1">
						<input class="inpt" placeholder="输入密码" @input="inputTyping" confirm-type="done"  v-model="PassWord"></input>
					</view>
				</view>
				<view class="cu-bar bg-white">
					<view class="action margin-0 flex-sub text-red solid-right" @tap="hideModal(0)">取消</view>
					<view class="action margin-0  flex-sub  text-blue solid-left" @tap="hideModal(1)">修改密码</view>
					<view class="action margin-0  flex-sub  text-blue solid-left" @tap="hideModal(2)">确定</view>
				</view>
			</view>
		</view>
		<view class="header margin-top">
			<view class="line"></view>
			<view class="header-contant" style="display: flex;">
				<view class="title1">设置内容</view>
				<view class="title2" style="float: right;">开启状态</view>
			</view>

		</view>
		<view class="block margin-top">
			<view class="cu-form-group" v-for="(item,index) in items" :key="item.index" style="display: flex;">
				<text class="title1" @tap="toPower(index)" style="flex:1;display: block;">{{item.User_Name}}</text>
				<jiuaiCheckbox @change='changeBox' :index="index" :value="item.IsUse !=''" :checked="item.IsUse !=''" ref="ck"></jiuaiCheckbox>
			</view>
		</view>
		<view class="bottom-contain">
			<view class="bottom-box">
				<view>
					<button @tap="getSystemPowerSettingInfo()">获取用户</button>
				</view>
				<view>
					<button @tap="DeleteAllUserRoot()">删除全部权限</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import * as Api from '@/syApis/sySet/sySet.js'
	import jiuaiCheckbox from "@/components/jiuai-checkbox.vue";
	export default {
		data() {
			return {
				PassWord: '',
				showMolde: true,
				focuspw: true,
				items: []

			}
		},
		created() {
			// this.getSystemSettingInfo();
			this.getSystemPowerSettingInfo();
		},
		components: {
			jiuaiCheckbox
		},
		methods: {
			DeleteAllUserRoot(){
				var that = this;
				let data = {};
				Api.Delete_All_UserRoot(data,function(res){
					if(res.state){
						if(res.data.ErrorMsg=='获取登录信息失败'){
							
						}else if(res.data.ErrorMsg!=""){
							
						}else{
							that.items = [];
							Api.showTip("删除成功");
						}
					}else{
						
					}
				})
			},
			//跳转到权限设置
			toPower(index) {
				let UserID = this.items[index].UserID;
				console.log(this.items[index].UserID + "nanannanan");
				uni.navigateTo({
					url: "../danju-Power/danju-Power?UserID=" + UserID
				})
			},
			//获取登录权限设置的内容
			getSystemPowerSettingInfo() {
				let data = {};
				var that = this;
				Api.Gain_User(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "No connection could be made because the target machine actively refused it") {

						} else if (res.data.ErrorMsg != "") {

						} else {
							// //console.tablele(res.data.ResultMsg)
							that.items = res.data.ResultMsg;
						}
					} else {
						Api.showTip("服务器超时")
					}
				})
			},
			changeBox(e) {

				var state = e.detail.value;
				var selectIndex = e.detail.index;
             
				let data = {
					UserID: this.items[e.detail.index].UserID,
					State: !state
				}
				// this.items[index].UserID;
				var that = this;
				Api.Update_UserState(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == '获取登录信息失败') {

						} else if (res.data.ErrorMsg != '') {
							Api.showTip(res.data.ErrorMsg);
							if (state == true) {
								that.items[selectIndex].IsUse = '√';
								that.$refs.ck[selectIndex].dataChecked = true;
							} else {
								that.items[selectIndex].IsUse = '';
								that.$refs.ck[selectIndex].dataChecked = false;
							}
						} else {
							Api.showTip("修改成功");
						}
					}
				})
				// let state = e.detail.value;
				// let selectIndex = e.detail.index;
				// if (state == true) {
				// 	this.items[selectIndex].IsUse = '';
				// } else {
				// 	this.items[selectIndex].IsUse = '√';
				// }
				// console.log(this.items[selectIndex])
			},
			inputTyping(e) {
				this.PassWord = e.detail.value
				console.log(this.PassWord)
			},
			hideModal(state) {
				// console.log(state)
				if (state == 0) {
					uni.navigateBack({
						delta: 1
					})
				}
				if (state == 1) {
					uni.navigateTo({
						url: "../setting/swtpw"
					})
				}
				if (state == 2) {
					if (this.PassWord.length == 0) {
						Api.showTip("密码不能为空");
						// this.showMolde = true
					} else {
						var that = this;
						let data = {
							PassWord: this.PassWord
						};
						Api.Gain_AdminPassword(data, function(res) {
							if (res.state) {
								if (res.data.ErrorMsg == '获取登录信息失败') {

								} else if (res.data.ErrorMsg != "") {
									Api.showTip(res.data.ErrorMsg);
								} else {
									if (res.data.TipsMsg == 'OK') {
										// Api.showTip("密码设置成功");
										that.showMolde = false;
									}

								}
							} else {
								Api.showTip("服务器超时");
							}
						});
					}
					// uni.setStorageSync("PassWord",this.PassWord);
					// log(this.PassWord);
				}
			},
			// getallset(){
			// 	console.log(1111)
			// }

		}
	}
</script>

<style>
	.header {
		background-color: #ffffff;
		padding: 0.5px 15px;
		display: -webkit-box;
		display: -webkit-flex;
		display: -ms-flexbox;
		display: flex;
	}

	.header-contant {
		display: flex;
		width: 100%;
		justify-content: space-between
	}

	.title1 {
		text-align: justify;
		padding-right: 15px;
		font-size: 15px;
		position: relative;
		min-height: 30px;
		line-height: 30px;
	}

	.title2 {
		font-size: 15px;
		position: relative;
		min-height: 30px;
		line-height: 30px;
	}

	.line {
		width: 5px;
		background-color: rgba(124, 170, 216, 1);
		position: relative;
		/* min-height: 19px;
		line-height: 18px; */
		margin-right: 10px;
	}

	.bottom-contain {
		position: absolute;
		/* bottom: 0; */
		width: 100%;
	}

	.bottom-box {
		width: 100%;
		position: fixed;
		bottom: 0;
		z-index: 999;
		width: 100%;
		display: flex;
	}
     .bottom-box view{
		 flex: 1;
		 
	 }
	.bottom-box button {
		width: 100%;
		width: 95%;
		margin: auto;
		color: #FFFFFF;
		background-color: rgba(124, 170, 216, 1);
		margin-bottom: 2px;
		font-size: 15px;
		flex: 1;
	}
	/* .block.margin-top{
	   padding-bottom: 80px;	
	} */
</style>
